﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.User;
using CE.Global;
using CE.Provider;

public partial class Provider_PersonalAccident_ViewBenefitScale : System.Web.UI.Page
{
    string PageName = "CXPA";
    string SubPageName = "CXPABS";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        if (!IsPostBack)
        {
            txtProviderComId.Text = Session[CE.Global.General.ProviderCompanyId].ToString();
            LoadPlanName();
        }
    }

    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/PersonalAccident/PAInsuranceHome.aspx");
    }

    protected void ddlPlanName_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void grvPABenefitscale_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[3].Text == "IND")
            {
                e.Row.Cells[3].Text = "Individual";
            }
            else if (e.Row.Cells[3].Text == "INDSP")
            {
                e.Row.Cells[3].Text = "Individual & Spouse";
            }
            else if (e.Row.Cells[3].Text == "INDCHD")
            {
                e.Row.Cells[3].Text = "Individual & Children";
            }
            else if (e.Row.Cells[3].Text == "INDSPCHD")
            {
                e.Row.Cells[3].Text = "Individual, Spouse & Children";
            }
        }
    }

    private void LoadPlanName()
    {
        CompareBenefitsDB _comparebenefitsdb = new CompareBenefitsDB();
        Int64 _PACompanyId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
        Int64 _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        DataTable _dtPlan = _comparebenefitsdb.GetPlanNames(_PACompanyId);
        //DataTable _dtPlan = _comparebenefitsdb.GetPlanNames(_PACompanyId, _UserId);
        _dtPlan.DefaultView.Sort = "PlanName asc";

        ddlPlanName.DataSource = _dtPlan.DefaultView.Table;
        ddlPlanName.DataValueField = _dtPlan.Columns[0].ColumnName.ToString();
        ddlPlanName.DataTextField = _dtPlan.Columns[0].ColumnName.ToString();
        ddlPlanName.DataBind();

        ddlPlanName.Items.Insert(0, new ListItem("Select", "-1"));
    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            lnkNewClaimInfo.Visible = false;
        }
    }

}
